<?php

/** libraries
 * http://docs.joomla.org/JToolBarHelper
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

class bgViewbg extends JView
{
	// Overwriting JView display method
	function display($tpl = null) 
	{
        $model = $this->getModel();
        
        $task = &JRequest::getVar('task');
        switch($task){
            case 'detail':
                //search
                $this->filter = &JRequest::getVar('jform');
                //Get data from model
                $master = new bgData();
                $this->listfacitype = $master->getFacilityType();
                $this->list_pede = $model->getListPede();
                $this->list_pref = $model->getListPref();
                
                //show
                $id = JRequest::getVar('id');
                $id = is_array($id) ? $id[0] : $id;
                if($id){
                    $this->row = $model->load($id);
                }
                /*else{
                    die("データは見つかりませんでした");
                }*/
                            
                $this->setLayout('detail');
            break;
            
            case 'icon':
                $this->setLayout('icon');
            break;
            case 'town':
            
                //search
                $this->filter = &JRequest::getVar('jform');
                //Get data from model
                $master = new bgData();
                $this->listfacitype = $master->getFacilityType();
                $this->list_pede = $model->getListPede();
                $this->list_pref = $model->getListPref();
                
                //show
                $id = JRequest::getVar('id');
                $id = is_array($id) ? $id[0] : $id;
                if($id){
                    $this->row = $model->loadTown($id);
                    $this->center_in_town = $model->loadCenterInTown($this->row->TOWN_CODE);
                    $this->info_ocba = $model->loadInfoOcba($id);
                }
                
                $this->setLayout('town');
            break;
            
            case 'club':
                //search
                $this->filter = &JRequest::getVar('jform');
                //Get data from model
                $master = new bgData();
                $this->listfacitype = $master->getFacilityType();
                $this->list_pede = $model->getListPede();
                $this->list_pref = $model->getListPref();
                
                //show
                $id = JRequest::getVar('id');
                $id = is_array($id) ? $id[0] : $id;
                if($id){
                    $this->rows = $model->loadClub($id);
                    $this->paginationClub =& $model->getPaginationClub($id);
                    
                    $this->info_ocba = $model->loadInfoOcba($id);
                }
                
                $this->setLayout('club');
            break;
            
            case 'activitive':
                //search
                $this->filter = &JRequest::getVar('jform');
                //Get data from model
                $master = new bgData();
                $this->listfacitype = $master->getFacilityType();
                $this->list_pede = $model->getListPede();
                $this->list_pref = $model->getListPref();
                
                //show
                $id = JRequest::getVar('id');
                $id = is_array($id) ? $id[0] : $id;
                if($id){
                    $this->rows = $model->loadActivity($id);
                    $this->paginationActivity =& $model->getPaginationActivity($id);
                    
                    $this->info_ocba = $model->loadInfoOcba($id);
                }
                
                $this->setLayout('activitive');
            break;
            
            case 'contact':
            
                //search
                $this->filter = &JRequest::getVar('jform');
                //Get data from model
                $master = new bgData();
                $this->listfacitype = $master->getFacilityType();
                $this->list_pede = $model->getListPede();
                $this->list_pref = $model->getListPref();
                
                //show
                $id = JRequest::getVar('id');
                $id = is_array($id) ? $id[0] : $id;
                if($id){
                    $this->row = $model->loadContact($id);
                    $this->info_ocba = $model->loadInfoOcba($id);
                }
                
                $this->setLayout('contact');
            break;
            
            case 'detail_activitive':
                $this->setLayout('detail_activitive');
            break;
            case 'facilities':
                $this->setLayout('facilities');
            break;
            case 'boat':
                $this->setLayout('boat');
            break;
            case 'boathouse':
            
                //search
                $this->filter = &JRequest::getVar('jform');
                //Get data from model
                $master = new bgData();
                $this->listfacitype = $master->getFacilityType();
                $this->list_pede = $model->getListPede();
                $this->list_pref = $model->getListPref();
                
                //show
                $id = JRequest::getVar('id');
                $id = is_array($id) ? $id[0] : $id;
                if($id){
                    $this->tbdo= $model->loadTbdo();
                    $this->row = $model->loadDock($id);
                    $this->info_ocba = $model->loadInfoOcba($id);
                }
                // echo json_encode($this->tbdo);
                // die;
                $this->setLayout('dock');
            break;
            case 'pool':
            
                //search
                $this->filter = &JRequest::getVar('jform');
                //Get data from model
                $master = new bgData();
                $this->listfacitype = $master->getFacilityType();
                $this->list_pede = $model->getListPede();
                $this->list_pref = $model->getListPref();
                $this->list_tbpo=$model->loadTbpo();
                $this->list_disp=$model->loadDisp();
                //show
                $id = JRequest::getVar('id');
                $id = is_array($id) ? $id[0] : $id;
                if($id){
                    $this->row = $model->loadPool($id);

                    $this->info_ocba = $model->loadInfoOcba($id);
                }
                
                $this->setLayout('pool');
            break;
            case 'gymt':
            
                //search
                $this->filter = &JRequest::getVar('jform');
                //Get data from model
                $master = new bgData();
                $this->listfacitype = $master->getFacilityType();
                $this->list_pede = $model->getListPede();
                $this->list_pref = $model->getListPref();
                 $this->tbgy= $model->loadTbgy();
                
                //show
                $id = JRequest::getVar('id');
                $id = is_array($id) ? $id[0] : $id;
                if($id){
                    $this->row = $model->loadGymt($id);
                    $this->info_ocba = $model->loadInfoOcba($id);
                }
                
                $this->setLayout('gymt');
            break;
            case 'coach':
                //search
                $this->filter = &JRequest::getVar('jform');
                //Get data from model
                $master = new bgData();
                $this->listfacitype = $master->getFacilityType();
                $this->list_pede = $model->getListPede();
                $this->list_pref = $model->getListPref();
                
                //show
                $id = JRequest::getVar('id');
                $id = is_array($id) ? $id[0] : $id;
                if($id){
                    $this->rows = $model->loadCoach($id);
                    $this->paginationCoch =& $model->getPaginationCoch($id);
                    
                    $this->info_ocba = $model->loadInfoOcba($id);                    
                }
                
                $this->setLayout('coach');
            break;
            
            case 'count_data':
            
                //load Google chart API
                $doc = JFactory::getDocument();
                $doc->addScript('https://www.google.com/jsapi');
                $doc->addScriptDeclaration("google.load('visualization', '1', {packages: ['corechart']});");
                $doc->addScriptDeclaration("google.load('visualization', '1', {packages: ['table']});");
            
                //search
                $this->filter = &JRequest::getVar('jform');
                //Get data from model
                $master = new bgData();
                $this->listfacitype = $master->getFacilityType();
                $this->list_pede = $model->getListPede();
                $this->list_pref = $model->getListPref();
                
                $year = JRequest::getVar('year');
                $id = JRequest::getVar('id');
                $filter = array(
                    'year' => empty($year) ? date('Y') : $year,
                    'month' => '04',
                    'id' => $id,
                );
                $result = $model->loadUsce($filter);
                $this->result = $result['statistic_data'];
                $this->chart = $result['chart_data'];
                $this->uscm = $model->getAllUscm();
                
                if($id){
                    $this->rows = $model->loadCountData($id);
                                        
                    $this->info_ocba = $model->loadInfoOcba($id);                    
                }
                
                $this->setLayout('count_data_year');
            break;
            case 'data_year':
                $this->setLayout('count_data_year');
            break;
            case 'print':     
                //Get data from model
                $this->filter = &JRequest::getVar('jform');
                $this->rows = $model->getAllCenterPrint($this->filter);
                $this->setLayout('print');
            break;
            case 'other_info':
            
                //search
                $this->filter = &JRequest::getVar('jform');
                //Get data from model
                $master = new bgData();
                $this->listfacitype = $master->getFacilityType();
                $this->list_pede = $model->getListPede();
                $this->list_pref = $model->getListPref();
                
                //show
                $id = JRequest::getVar('id');
                $id = is_array($id) ? $id[0] : $id;
                if($id){
                    $this->row = $model->loadOther_Info($id);
                    $master = new bgData();
                    $this->listdm = $master->getDMClassification();
                    //get activity
                    $this->listacti = $master->getActivity();
                    //get facility
                    $this->listfacitype = $master->getFacilityType();                    
                }
                
                $this->setLayout('other_info');
            break;
            case 'export':
                $csv_output = JRequest::getVar('csv_data');
                $csv_output = mb_convert_encoding($csv_output,'Shift-JIS','UTF-8');
                $filename = "statistic_".date("Y-m-d_H-i",time());
                
        
                header("Content-Encoding: Shift-JIS");
                header("Content-Type: text/csv; charset= Shift-JIS");
                header("Content-disposition: csv" . date("Y-m-d") . ".csv");
                header("Content-disposition:attachment; filename=" . $filename . ".csv");
                print_r($csv_output);
                
                $app = &JFactory::getApplication();
                $app->close();
            break;
            
            default :
                //check submit search
                $check = &JRequest::getVar('check');
                if($check == '1')
                {
                    $this->sr = '1';
                }
                else $this->sr = '0';
                
                //search
                $this->filter = &JRequest::getVar('jform');
                
                //Get data from model
                $master = new bgData();
                $this->listfacitype = $master->getFacilityType();
                $this->list_pede = $model->getListPede();
                $this->list_pref = $model->getListPref();
                $this->rows = $model->getAllCenter($this->filter);
                $this->setLayout('default');
                $this->pagination =& $model->getPagination();
        }
        
		parent::display();
	}
}




